package com.orange.modules.dao;

import java.sql.SQLException;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.orange.dbhelp.DbHelper;
import com.orange.modules.entity.school_data.AuthMoneyResource;

@Repository
public class AuthMoneyResourceRepository {
	@Autowired
	private DbHelper dbHelper;
	
	@Autowired
	private AuthMoneyResourceDataDao authMoneyResourceDataDao;
	
	public void insertMoneyResource(AuthMoneyResource amr) throws SQLException{
		authMoneyResourceDataDao.save(amr);
	}
	
	
	public AuthMoneyResource queryAuthMoneyResourcesBySchoolId(String schoolId,String loginType) throws SQLException{
		String sql = "SELECT t.p_id as pid ,s_training_funds as trainingFunds,"
				+ "t.s_professional_training_funds as professionalTrainingFunds,t.s_budget_standards as budgetStandards,"
				+ "t.s_were_born as wereBorn,t.s_average_education_funding_ratio as averageEducationFundingRatio,"
				+ "t.s_outlay_per_student as outlayPerStudent,t.s_equipment_investment as equipmentInvestment,"
				+ "t.s_professional_library_funding as professionalLibraryFunding,t.s_funding_education_funding_per as fundingEducationFundingPer,"
				+ "t.s_createtime as createtime,t.s_id as sid,t.login_type as logintype,t.s_status as status,t.s_remark as remark FROM t_auth_money_resource t WHERE t.s_id =?";
		if(StringUtils.isNotBlank(loginType)){
			sql+="AND  t.login_type ='"+loginType+"'";
		}
		
		AuthMoneyResource amr = dbHelper.getBean(sql, AuthMoneyResource.class,schoolId);
		return amr;
	}
}
